import 'dart:convert';

import 'package:bike_ride/api/api_defines.dart';
import 'package:bike_ride/api/req.dart';
import 'package:bike_ride/common/net/base_repository.dart';
import 'package:bike_ride/common/net/dio_client.dart';
import 'package:bike_ride/common/net/dio_response.dart';
import 'package:bike_ride/common/util/account_manager.dart';
import 'package:bike_ride/common/util/extension.dart';
import 'package:bike_ride/generated/l10n.dart';
import 'package:bike_ride/model/cyling/model/bike_real_time_m.dart';
import 'package:bike_ride/model/cyling/model/borrow_bike_m.dart';
import 'package:bike_ride/model/cyling/model/server_time_m.dart';
import 'package:bike_ride/model/cyling/model/unpay_info_m.dart';
import 'package:bike_ride/model/fault_report/model/server_parts_m.dart';
import 'package:bike_ride/model/login/model/map_address_m.dart';
import 'package:bike_ride/model/login/model/vehicle_geog_list_item_model.dart';
import 'package:bike_ride/model/main/model/area_info_m.dart';
import 'package:bike_ride/model/main/model/brand_info_m.dart';
import 'package:bike_ride/model/main/model/cmall_card_m.dart';
import 'package:bike_ride/model/main/model/park_m.dart';
import 'package:bike_ride/model/main/model/pmt_m.dart';
import 'package:bike_ride/model/main/model/user_info_m.dart';
import 'package:bike_ride/model/mine/model/finance_stat_m.dart';
import 'package:bike_ride/model/pay/model/overseas_pay_m.dart';
import 'package:bike_ride/model/pay/model/payed_order_detail_m.dart';
import 'package:bike_ride/model/protocol/model/contract_m.dart';
import 'package:bike_ride/model/question/model/question_m.dart';
import 'package:bike_ride/model/scan/model/scan_m.dart';
import 'package:bike_ride/model/unlock/model/bike_info_m.dart';
import 'package:bike_ride/model/wallet/model/open_pay_create_order_m.dart';
import 'package:bike_ride/model/wallet/model/recharge_arrow_m.dart';
import 'package:bike_ride/model/wallet/model/recharge_info_m.dart';
import 'package:bike_ride/model/wallet/model/refund_info_m.dart';
import 'package:bike_ride/model/wallet/model/transaction_item_m.dart';
import 'package:dio/dio.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';

class CommonRepository extends BaseRepository {
  /// 经纬度逆地址
  static Future<MapAddressModel?> getAddressByLgoIdl({
    CancelToken? cancelToken,
    required num lat,
    required num lng,
  }) async {
    final response = await DioClient().doPost(kAPIURLMapAddress,
        cancelToken: cancelToken, data: {'latitude': lat, 'longitude': lng});
    if (response.statusCode == REQUEST_SUCCESS) {
      return MapAddressModel.fromJson(response.data);
    } else {
      DioClient.showError(response);
      return null;
    }
  }

  /// 附近车辆信息取areaCode
  static Future<String> getAreaCodeByNearByBikeIdl({
    CancelToken? cancelToken,
    required num lat,
    required num lng,
  }) async {
    final result =
        await getNearbyBikeIdl(cancelToken: cancelToken, lat: lat, lng: lng);
    if (result.isNotEmpty) {
      return result.first.areaId ?? '';
    } else {
      return '';
    }
  }

  /// 附近车辆
  static Future<List<VehicleGeogListItem>> getNearbyBikeIdl({
    CancelToken? cancelToken,
    required num lat,
    required num lng,
  }) async {
    if(!AccountManager.isLogin)return [];
    final response = await DioClient()
        .doPost(kAPIURLGeogBike, cancelToken: cancelToken, data: {
      'lat': lat,
      'lng': lng,
      'hidden_time': 35 * 60,
      'is_available': 1,
    });
    if (response.statusCode == REQUEST_SUCCESS) {
      return vehicleGeogListFromJson(json.encode(response.data ?? []));
    } else {
      DioClient.showError(response);
      return [];
    }
  }


  /// 附近停车场
  static Future<List<ParkM>> getNearbyParkIdl({
    CancelToken? cancelToken,
    required num lat,
    required num lng,
    int type = 1,
    bool isShowEmptyTip = false,
  }) async {
    final response = await DioClient().doPost(kAPIURLGeogPark,
        cancelToken: cancelToken, data: {'lat': lat, 'lng': lng, 'type': type});
    if (response.statusCode == REQUEST_SUCCESS) {
      final list = response.toList().map((e) => ParkM.fromJson(e)).toList();
      if(list.isEmpty && isShowEmptyTip){
        EasyLoading.showError(S.current.NoParkNear);
      }
      return list;
    } else {
      DioClient.showError(response);
      return [];
    }
  }

  /// 待支付违规订单
  Future<List<ViolationUnPay>> getUnPayViolationIdl({
    CancelToken? cancelToken,
  }) async {
    final response = await DioClient().doPost(kAPIURLViolationUnpay,
        cancelToken: cancelToken, data: {'page': 1, 'list_rows': 2});
    if (response.statusCode == REQUEST_SUCCESS) {
      return response.toList().map((e) => ViolationUnPay.fromJson(e)).toList();
    } else {
      DioClient.showError(response);
      return [];
    }
  }

  /// 未支付订单
  static Future<List<UnPayInfoM>> getUnPayOrderIdl({
    CancelToken? cancelToken,
    int page = 1,
  }) async {
    final response = await DioClient().doPost(kAPIURLOrderUnpay,
        cancelToken: cancelToken, data: {'page': page, 'list_rows': 10});
    if (response.statusCode == REQUEST_SUCCESS) {
      return response.toList().map((e) => UnPayInfoM.fromJson(e)).toList();
    } else {
      DioClient.showError(response);
      return [];
    }
  }

  /// 获取未支付的订单信息
  static Future<UnPayInfoM?> getUnPayInfoIdl({
    CancelToken? cancelToken,
    String? orderId,
  }) async {
    EasyLoading.show();
    final response = await DioClient().doPost(kAPIURLUnPayInfo,
        cancelToken: cancelToken, data: {'order_id': orderId});
    EasyLoading.dismiss();
    if (response.statusCode == REQUEST_SUCCESS) {
      return UnPayInfoM.fromJson(response.data);
    } else {
      DioClient.showError(response);
      return null;
    }
  }

  /// 余额支付
  static Future<bool> getBalancePayIdl({
    CancelToken? cancelToken,
    String? orderId,
    num? totalAmount,
    required int actionType,
    ReturnBikeReq? returnBikeReq,
  }) async {
    EasyLoading.show();
    final params =  {
      'use_balance': 1,
      'platform': 1,
      'action_type': actionType,
      'total_amount': totalAmount,
      'target_id': orderId,
    };
    if(returnBikeReq != null){
      params['return_bike_data'] = returnBikeReq.toJson();
    }
    final response = await DioClient()
        .doPost(kAPIURLBalancePay, cancelToken: cancelToken, data: params);
    if (response.statusCode == REQUEST_SUCCESS) {
      EasyLoading.showSuccess('success');
      return true;
    } else {
      DioClient.showError(response);
      return false;
    }
  }

  /// 海外支付
  /// [actionType]
  //1：余额充值
  // 2：支付押金
  // 3：支付订单
  // 4：购买骑行卡
  // 5：预付款骑行
  // 6：支付先付款后还车订单
  // 7：违规订单
  // 8：支付分骑行
  // 9：购买押金卡
  // 10：自动完结骑行订单
  static Future<OverseasPayM?> getOverseasOpenPayIdl({
    CancelToken? cancelToken,
    String? orderId,
    num? totalAmount,
    num? actionType,
    ReturnBikeReq? returnBikeReq,
  }) async {
    EasyLoading.show();
    final params =  {
      'platform': 1,
      'action_type': actionType,
      'total_amount': totalAmount,
      'target_id': orderId
    };
    if(returnBikeReq != null){
      params['return_bike_data'] = returnBikeReq.toJson();
    }
    final response = await DioClient()
        .doPost(kAPIURLOverseasPay, cancelToken: cancelToken, data: params);
    if (response.statusCode == REQUEST_SUCCESS) {
      EasyLoading.dismiss();
      return OverseasPayM.fromJson(response.data);
    } else {
      DioClient.showError(response);
      return null;
    }
  }

  /// 海外支付(Fiuu支付)
  /// [actionType]
  //1：余额充值
  // 2：支付押金
  // 3：支付订单
  // 4：购买骑行卡
  // 5：预付款骑行
  // 6：支付先付款后还车订单
  // 7：违规订单
  // 8：支付分骑行
  // 9：购买押金卡
  // 10：自动完结骑行订单
  /// [payChanel] fiuu 的pay_chanel = 12；印尼 的pay_chanel = 13
  static Future<FiuuPayM?> getOverseasH5PayIdl({
    CancelToken? cancelToken,
    String? orderId,
    num? totalAmount,
    num? actionType,
    ReturnBikeReq? returnBikeReq,
    required num payChanel,
  }) async {
    EasyLoading.show();
    final params =  {
      'platform': 1,
      'action_type': actionType,
      'total_amount': totalAmount,
      'target_id': orderId,
      'pay_chanel': payChanel,
    };
    if(returnBikeReq != null){
      params['return_bike_data'] = returnBikeReq.toJson();
    }
    final response = await DioClient()
        .doPost(kAPIURLCreateOrderOverseasPay, cancelToken: cancelToken, data: params);
    if (response.statusCode == REQUEST_SUCCESS) {
      EasyLoading.dismiss();
      return FiuuPayM.fromJson(response.data);
    } else {
      DioClient.showError(response);
      return null;
    }
  }

  /// 海外支付状态
  static Future<bool> getOverseasPayStatusIdl({
    CancelToken? cancelToken,
    String? outTradeNo,
  }) async {
    final response = await DioClient()
        .doPost(kAPIURLOverseasPayStatus, cancelToken: cancelToken, data: {
      'out_trade_no': outTradeNo,
    });
    if (response.statusCode == REQUEST_SUCCESS) {
      if(response.data['pay_status'] == 300){
        return true;
      }
    } else {
      // DioClient.showError(response);
    }
    return false;
  }


  /// 已完成支付订单详情
  static Future<PayedOrderDetailM?> getFinishOrderDetailIdl({
    CancelToken? cancelToken,
    String? orderId,
  }) async {
    final response = await DioClient()
        .doPost(kAPIURLFinishOrderDetail, cancelToken: cancelToken, data: {
      'order_id': orderId
    });
    if (response.statusCode == REQUEST_SUCCESS) {
      return PayedOrderDetailM.fromJson(response.data);
    } else {
      DioClient.showError(response);
      return null;
    }
  }

  /// 已完成、退款订单列表
  /// [status] null:默认返回已完成，2：退款订单
  static Future<List<UnPayInfoM>> getFinishOrderListIdl({
    CancelToken? cancelToken,
    int? status,
    int page = 1,
  }) async {
    final response = await DioClient()
        .doPost(kAPIURLFinishOrderList, cancelToken: cancelToken, data: {
      'status': status,
      'page': page,
      'list_rows': 10,
    });
    if (response.statusCode == REQUEST_SUCCESS) {
      return response.toList().map((e) => UnPayInfoM.fromJson(e)).toList();
    } else {
      DioClient.showError(response);
      return [];
    }
  }

  /// 获取服务器时间
  static Future<ServerTimeM?> getServerTimeIdl({
    CancelToken? cancelToken,
  }) async {
    final response = await DioClient().doPost(kAPIURLServiceTime,
        cancelToken: cancelToken);
    if (response.statusCode == REQUEST_SUCCESS) {
      return ServerTimeM.fromJson(response.data);
    } else {
      DioClient.showError(response);
      return null;
    }
  }

  /// 订单是否进行中
  static Future<bool> getOrderNoExistIdl({
    CancelToken? cancelToken,
    required String vid,
  }) async {
    final response = await DioClient().doPost(kAPIURLOrderExist,
        cancelToken: cancelToken,data: {'vid':vid});
    if (response.statusCode == REQUEST_SUCCESS) {
      return response.data == 0;//0：订单结束、1：进行中
    } else {
      DioClient.showError(response);
      //避免因为网络异常原因导致离开页面
      return false;
    }
  }
  /// 借车
  static Future<BorrowBikeM> borrowBikeIdl({
    CancelToken? cancelToken,
    required num lat,
    required num lng,
    required String vid,
  }) async {
    final response = await DioClient().doPost(kAPIURLBikeBorrow,
        cancelToken: cancelToken,data: {'ug':lng,'lat':lat,'source':3,'vid':vid});
    if (response.statusCode == REQUEST_SUCCESS) {
      return BorrowBikeM.fromJson(response.data);
    } else {
      return BorrowBikeM.error(response.statusMessage??'');
    }
  }
  /// 临时锁车
  /// [sw] 1：临时锁车，2：临时锁车开锁
  static Future<Response> tempLockBikeIdl({
    CancelToken? cancelToken,
    required String orderId,
    required String vid,
    required int sw,
  }) async {
    final result = await DioClient().doPost(kAPIURLBikeTempLock,
        cancelToken: cancelToken,data: {'sw':sw,'order_id':orderId,'vid':vid});
    return result;
  }

  /// 还车
  /// [isOpenPrepayEndOrder] 先付后还
  static Future<Response> returnBikeIdl({
    CancelToken? cancelToken,
    bool? isOpenPrepayEndOrder,
    required ReturnBikeReq req,
  }) async {
    return await DioClient()
        .doPost(isOpenPrepayEndOrder == true ? kAPIURLBikeReturnFee : kAPIURLBikeReturn, cancelToken: cancelToken, data: req.toJson());
  }

  /// 先付款后还车查询骑行费用
  static Future<Response> returnBikeFeeIdl({
    CancelToken? cancelToken,
    required String orderId,
    required String vid,
    required num lat,
    required num lng,
    int? skipParkingCheck = 0,
    int? skipHelmetCheck = 0,
    int? skip90degCheck = 0,
    int? studyFreeTraffic = 0,
  }) async {
    return await DioClient()
        .doPost(kAPIURLBikeReturnFee, cancelToken: cancelToken, data: {
      'ug': lng,
      'ut': lat,
      'order_id': orderId,
      'vid': vid,
      'skip_parking_check': skipParkingCheck,
      'skip_helmet_check': skipHelmetCheck,
      'skip_90deg_check': skip90degCheck,
      'study_free_traffic': studyFreeTraffic,
    });
  }

  /// 校验是否在站点内
  static Future<ParkM?> checkParkingIdl({
    CancelToken? cancelToken,
    required num lat,
    required num lng,
  }) async {
    final response = await DioClient().doPost(kAPIURLCheckParking,
        cancelToken: cancelToken, data: {
      'lng': lng,
      'lat': lat, 'type': 1,
      'default_return_bike_radius':
          AccountManager.areaInfoM?.defaultReturnBikeRadius,
      'is_judge_user_coordinates':
          AccountManager.areaInfoM?.isJudgeUserCoordinates,
      'judge_user_coordinates_radius':
          AccountManager.areaInfoM?.judgeUserCoordinatesRadius
    });
    if (response.statusCode == REQUEST_SUCCESS) {
      return ParkM.fromJson(response.data);
    } else {
      DioClient.showError(response);
      return null;
    }
  }

  /// 解锁头盔
  static Future<Response> helmetUnlockIdl({
    CancelToken? cancelToken,
    required String orderId,
    required String vid,
  }) async {
    return await DioClient().doPost(kAPIURLHelmetUnlock,
        cancelToken: cancelToken,data: {'order_id':orderId,'vid':vid});
  }

  /// 品牌信息
  static Future<BrandInfoM?> getBrandInfoIdl({
    CancelToken? cancelToken,
  }) async {
    final response =
        await DioClient().doPost(kAPIURLBrandInfo, cancelToken: cancelToken);
    if (response.statusCode == REQUEST_SUCCESS) {
      return BrandInfoM.fromJson(response.data);
    } else {
      DioClient.showError(response);
      return null;
    }
  }

  /// 区域信息
  static Future<AreaInfoM?> getBrandAreaInfoIdl({
    CancelToken? cancelToken,
  }) async {
    final response = await DioClient().doPost(
      kAPIURLBrandAreaInfo,
      cancelToken: cancelToken,
    );
    if (response.statusCode == REQUEST_SUCCESS) {
      return AreaInfoM.fromJson(response.data);
    } else {
      DioClient.showError(response);
      return null;
    }
  }

  /// 广告信息
  /// [position] 广告位置
  static Future<List<PmtM>> getPmtDataIdl({
    CancelToken? cancelToken,
    String? position,
  }) async {
    final response = await DioClient().doPost(kAPIURLPmtData,
        data: {"position": position}, cancelToken: cancelToken);
    if (response.statusCode == REQUEST_SUCCESS) {
      return pmtMListFromJson(json.encode(response.data ?? []));
    } else {
      DioClient.showError(response);
      return [];
    }
  }

  /// 骑行卡信息
  static Future<CmallCardM?> getCmallCardsIdl({
    CancelToken? cancelToken,
    int page = 1,
  }) async {
    final response = await DioClient().doPost(kAPIURLCmallCards,
        data: {
          "is_pay_recommend": 0,
          "is_recommend": 1,
          'page': page,
          'list_rows': 10
        },
        cancelToken: cancelToken);
    if (response.statusCode == REQUEST_SUCCESS) {
      return CmallCardM.fromJson(response.data);
    } else {
      DioClient.showError(response);
      return null;
    }
  }

  /// 获取用户信息
  static Future<UserInfoM?> getUserInfoIdl({
    CancelToken? cancelToken,
  }) async {
    final response = await DioClient().doPost(kAPIURLUserInfo,cancelToken: cancelToken);
    if (response.statusCode == REQUEST_SUCCESS) {
      return UserInfoM.fromJson(response.data);
    } else {
      DioClient.showError(response);
      return null;
    }
  }

  /// 车辆信息
  static Future<BikeInfoM?> getBikeInfoIdl({
    CancelToken? cancelToken,
    required String vid,
  }) async {
    final response = await DioClient().doPost(kAPIURLBikeInfo,cancelToken: cancelToken,data: {'vid':vid});
    if (response.statusCode == REQUEST_SUCCESS) {
      return BikeInfoM.fromJson(response.data);
    } else {
      DioClient.showError(response);
      return null;
    }
  }

  /// 车辆实时信息
  static Future<BikeRealTimeM?> getBikeRealTimeIdl({
    CancelToken? cancelToken,
    required String vid,
  }) async {
    final response = await DioClient().doPost(kAPIURLBikeRealTime,cancelToken: cancelToken,data: {'vid':vid});
    if (response.statusCode == REQUEST_SUCCESS) {
      return BikeRealTimeM.fromJson(response.data);
    } else {
      DioClient.showError(response);
      return null;
    }
  }

  /// 帮助中心
  static Future<List<QuestionM>> getHelpListIdl({
    CancelToken? cancelToken,
  }) async {
    EasyLoading.show();
    final response = await DioClient().doPost(kAPIURLHelpList,
        data: {"page": 1, "list_rows": 20, "platform": "wechat", "type": 0},
        cancelToken: cancelToken);
    if (response.statusCode == REQUEST_SUCCESS) {
      EasyLoading.dismiss();
      return response.toList().map((e) => QuestionM.fromJson(e)).toList();
    } else {
      DioClient.showError(response);
      return [];
    }
  }

  /// 退出登录
  static Future<bool> signOutIdl({
    CancelToken? cancelToken,
  }) async {
    final response =
        await DioClient().doPost(kAPIURLLogout, cancelToken: cancelToken);
    return response.statusCode == REQUEST_SUCCESS;
  }

  /// 统计优惠券、骑行卡
  static Future<FinanceStatM?> getStatDiscountIdl({
    CancelToken? cancelToken,
  }) async {
    final response = await DioClient().doPost(kAPIURLStatDiscount, cancelToken: cancelToken);
    if (response.statusCode == REQUEST_SUCCESS) {
      return FinanceStatM.fromJson(response.data);
    } else {
      return null;
    }
  }

  /// 统计余额
  static Future<DiscountStatM?> getFinanceInfoIdl({
    CancelToken? cancelToken,
  }) async {
    final response = await DioClient().doPost(kAPIURLFinanceInfo, cancelToken: cancelToken);
    if (response.statusCode == REQUEST_SUCCESS) {
      return DiscountStatM.fromJson(response.data);
    } else {
      DioClient.showError(response);
      return null;
    }
  }
  /// 充值记录
  static Future<List<RechargeArrowM>> getRechargeArrowListIdl({
    CancelToken? cancelToken,
  }) async {
    final response = await DioClient().doPost(kAPIURLRechargeArrow, cancelToken: cancelToken);
    if (response.statusCode == REQUEST_SUCCESS) {
      return response.toList().map((e) => RechargeArrowM.fromJson(e)).toList();
    } else {
      DioClient.showError(response);
      return [];
    }
  }

  /// 申请退款中信息
  static Future<RefundInfoM?> getRefundInfoIdl({
    CancelToken? cancelToken,
  }) async {
    final response = await DioClient().doPost(kAPIURLRefundInfo, cancelToken: cancelToken);
    if (response.statusCode == REQUEST_SUCCESS) {
      return RefundInfoM.fromJson(response.data?? {});
    } else {
      DioClient.showError(response);
      return null;
    }
  }

  /// 充值赠送活动
  static Future<RechargeInfoM?> getRechargeInfoIdl({
    CancelToken? cancelToken,
  }) async {
    final response = await DioClient().doPost(kAPIURLRechargeInfo, cancelToken: cancelToken);
    if (response.statusCode == REQUEST_SUCCESS) {
      return RechargeInfoM.fromJson(response.data);
    } else {
      DioClient.showError(response);
      return null;
    }
  }

  /// openPay创建订单
  static Future<OpenPayCreateOrderM?> openPayCreateOrderIdl({
    CancelToken? cancelToken,
    required num totalAmount,
    required int actionType,
  }) async {
    EasyLoading.show(status: '${S.current.createOrdering}...');
    final response = await DioClient().doPost(kAPIURLCreateOrder, cancelToken: cancelToken,data: {
      'pay_type':AccountManager.brandInfo?.payType??0,
      'platform':1,
      'total_amount': totalAmount,
      'use_balance':0,
      'action_type':actionType,
    });
    if (response.statusCode == REQUEST_SUCCESS) {
      EasyLoading.showSuccess(S.current.createOrderSuccess);
      return OpenPayCreateOrderM.fromJson(response.data);
    } else {
      DioClient.showError(response);
      return null;
    }
  }

  /// 申请退款
  static Future<bool> rechargeRefundApplyIdl({
    CancelToken? cancelToken,
    required List<String> imgUrl,
    required String remark,
    required String orderId,
  }) async {
    EasyLoading.show();
    final response = await DioClient().doPost(kAPIURLRechargeRefundApply, cancelToken: cancelToken,data: {
      'img_url': imgUrl,
      'remark': remark,
      'order_id': orderId,
    });
    if (response.statusCode == REQUEST_SUCCESS) {
      EasyLoading.showSuccess(S.current.refundSubmitSuccess);
      return true;
    } else {
      DioClient.showError(response);
      return false;
    }
  }

  /// 交易明细列表
  /// [inOrOut] 0：支出与收入，1：收入 2，支出
  static Future<List<TransactionItemM>> getTransactionsIdl({
    CancelToken? cancelToken,
    required int inOrOut,
    required int page,
    required int listRows,
  }) async {
    final response = await DioClient().doPost(kAPIURLTransactions, cancelToken: cancelToken,data: {
      'in_or_out': inOrOut,
      'list_rows': listRows,
      'page': page,
    });
    if (response.statusCode == REQUEST_SUCCESS) {
      return response.toList().map((e) => TransactionItemM.fromJson(e)).toList();
    } else {
      DioClient.showError(response);
      return [];
    }
  }

  /// 获取协议列表
  static Future<List<ContractM>> getContractsIdl({
    CancelToken? cancelToken,
  }) async {
    EasyLoading.show();
    final response = await DioClient().doPost(kAPIURLContracts, cancelToken: cancelToken,);
    EasyLoading.dismiss();
    if (response.statusCode == REQUEST_SUCCESS) {
      return response.toList().map((e) => ContractM.fromJson(e)).toList();
    } else {
      DioClient.showError(response);
      return [];
    }
  }

  /// 签署协议
  static Future<bool> signContractsIdl({
    CancelToken? cancelToken,
    List<num>? contractIds,
  }) async {
    EasyLoading.show();
    final response = await DioClient().doPost(kAPIURLSignContracts, cancelToken: cancelToken,data: {'contract_ids': contractIds});
    EasyLoading.dismiss();
    return response.statusCode == REQUEST_SUCCESS;
  }

  /// 上传图片
  static Future<String> uploadImgIdl({
    CancelToken? cancelToken,
    required String imgData,
  }) async {
    EasyLoading.show();
    final response = await DioClient().doPost(kAPIURLUploadImg, cancelToken: cancelToken,data: {'image_data': imgData});
    EasyLoading.dismiss();
    if(response.statusCode == REQUEST_SUCCESS && response.data != null && response.data['url'] != null){
      EasyLoading.showSuccess(S.current.uploadSuccess);
      return response.data['url'];
    }else{
      DioClient.showError(response);
      return '';
    }
  }

  /// 获取故障部件列表
  static Future<List<ServerPartsM>> getServerPartsIdl({
    CancelToken? cancelToken,
  }) async {
    EasyLoading.show();
    final response = await DioClient().doPost(kAPIURLServerParts, cancelToken: cancelToken,data: {'platform': 'miniapp'});
    EasyLoading.dismiss();
    if(response.statusCode == REQUEST_SUCCESS && response.data != null){
      return response.toList().map((e) => ServerPartsM.fromJson(e)).toList();
    }else{
      DioClient.showError(response);
      return [];
    }
  }

  /// 故障上报
  static Future<bool> faultReportIdl({
    CancelToken? cancelToken,
    String? vid,
    String? place,
    String? orderId,
    num? lat,
    num? lng,
    List<String>? imgurl,
    String? content,
  }) async {
    final response = await DioClient().doPost(kAPIURLFaultReport, cancelToken: cancelToken,data: {
      'vid': vid,
      'place': place,
      'order_id': orderId,
      'lat': lat,
      'lng':lng,
      'is_current':0,
      'imgurl': imgurl,
      'content': content,
    });
    if(response.statusCode != REQUEST_SUCCESS){
      DioClient.showError(response);
    }
    return response.statusCode == REQUEST_SUCCESS;
  }
}
